home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue25 / hipsquar / TEXT.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1997-06-07  |  4.8 KB  |  183 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {     Creating Non-Rectangular Windows                    }
  4. {                                                         }
  5. {     Requires Win32 API (Delphi 2.0 or 3.0 or newer)     }
  6. {                                                         }
  7. {     Copyright ⌐ 1997 Steven J. Colagiovanni             }
  8. {                                                         }
  9. {*********************************************************}
  10.  
  11. unit Text;
  12.  
  13. interface
  14.  
  15. uses
  16.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  17.  
  18. type
  19.     TfrmText = class(TForm)
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  22.       Shift: TShiftState);
  23.     procedure FormPaint(Sender: TObject);
  24.   private
  25.         { Private declarations }
  26.         procedure WMNCHitTest(Var Msg: TMessage); message WM_NCHITTEST;
  27.         procedure ConstructPath;
  28.     public
  29.         { Public declarations }
  30.     end;
  31.  
  32. var
  33.     frmText: TfrmText;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38.  
  39. procedure TfrmText.WMNCHitTest(Var Msg: TMessage);
  40. begin
  41.     { Respond to left mouse button down, so we can drag window }
  42.     if GetAsyncKeyState(VK_LButton) < 0 then
  43.         Msg.Result := HTCaption
  44.     else
  45.         Msg.Result := HTClient;
  46.  
  47.     { if right mouse button down, close window }
  48.     if GetAsyncKeyState(VK_RButton) < 0 then
  49.         Close;
  50. end;
  51.  
  52. procedure TfrmText.ConstructPath;
  53. var
  54.     RgnPts: array[0..11] of TPoint;
  55.     MagLength: word;
  56.  
  57. begin
  58.     BeginPath(Canvas.Handle);
  59.     { SetBkMode() allows us to outline letters }
  60.     SetBkMode(Canvas.Handle, TRANSPARENT);
  61.  
  62.     with canvas do
  63.     begin
  64.         { Use canvas to paint 'Delphi' }
  65.         Font.Style := [fsBold];
  66.         Font.Name := 'Times New Roman';
  67.         Font.Size := 130;
  68.         TextOut(62, 0, 'Delphi');
  69.  
  70.         { Use canvas to paint 'MAGAZINE' }
  71.         { Square is ANSI character 0183 }
  72.         Font.Name := 'Arial';
  73.         Font.Size := 37;
  74.         TextOut(0, 195, 'M ╖ A ╖ G ╖ A ╖ Z ╖ I ╖ N ╖ E');
  75.  
  76.         { Get length of text before changing font }
  77.         MagLength := TextWidth('M ╖ A ╖ G ╖ A ╖ Z ╖ I ╖ N ╖ E');
  78.  
  79.     end;
  80.  
  81.     { 'E' }
  82.     RgnPts[0] := Point(0, 44);
  83.     RgnPts[1] := Point(12, 44);
  84.     RgnPts[2] := Point(12, 66);
  85.     RgnPts[3] := Point(21, 66);
  86.     RgnPts[4] := Point(21, 44);
  87.     RgnPts[5] := Point(32, 44);
  88.     RgnPts[6] := Point(32, 66);
  89.     RgnPts[7] := Point(41, 66);
  90.     RgnPts[8] := Point(41, 44);
  91.     RgnPts[9] := Point(53, 44);
  92.     RgnPts[10] := Point(53, 78);
  93.     RgnPts[11] := Point(0, 78);
  94.     Polygon(Canvas.Handle, RgnPts[0], 12);
  95.  
  96.     { 'H' }
  97.     RgnPts[0] := Point(0, 83);
  98.     RgnPts[1] := Point(53, 83);
  99.     RgnPts[2] := Point(53, 95);
  100.     RgnPts[3] := Point(32, 95);
  101.     RgnPts[4] := Point(32, 106);
  102.     RgnPts[5] := Point(53, 106);
  103.     RgnPts[6] := Point(53, 118);
  104.     RgnPts[7] := Point(0, 118);
  105.     RgnPts[8] := Point(0, 106);
  106.     RgnPts[9] := Point(21, 106);
  107.     RgnPts[10] := Point(21, 95);
  108.     RgnPts[11] := Point(0, 95);
  109.     Polygon(Canvas.Handle, RgnPts[0], 12);
  110.  
  111.     { 'T' }
  112.     RgnPts[0] := Point(0, 123);
  113.     RgnPts[1] := Point(13, 123);
  114.     RgnPts[2] := Point(13, 135);
  115.     RgnPts[3] := Point(53, 135);
  116.     RgnPts[4] := Point(53, 148);
  117.     RgnPts[5] := Point(13, 148);
  118.     RgnPts[6] := Point(13, 158);
  119.     RgnPts[7] := Point(0, 158);
  120.     Polygon(Canvas.Handle, RgnPts[0], 8);
  121.  
  122.     { Create two underlines }
  123.     MoveToEx(Canvas.Handle, 0, 165, nil);
  124.     LineTo(Canvas.Handle, 311, 165);
  125.     LineTo(Canvas.Handle, 311, 175);
  126.     LineTo(Canvas.Handle, 0, 175);
  127.     LineTo(Canvas.Handle, 0, 165);
  128.  
  129.     MoveToEx(Canvas.Handle, 365, 165, nil);
  130.     { Right end point = end of text }
  131.     LineTo(Canvas.Handle, MagLength-1, 165);
  132.     LineTo(Canvas.Handle, MagLength-1, 175);
  133.     LineTo(Canvas.Handle, 365, 175);
  134.     LineTo(Canvas.Handle, 365, 165);
  135.  
  136.     EndPath(Canvas.Handle);
  137. end;
  138.  
  139. procedure TfrmText.FormCreate(Sender: TObject);
  140. var
  141.     Region1: hRgn;
  142. begin
  143.     ConstructPath;
  144.     { Create region, or window boundaries from the constructed Path }
  145.     Region1 := PathToRegion(Canvas.Handle);
  146.     { Assign the region to the window }
  147.     SetWindowRgn(Handle, Region1, True);
  148.  
  149.     { Do not delete region - Windows now has control
  150.         of the region. }
  151. end;
  152.  
  153. procedure TfrmText.FormKeyDown(Sender: TObject; var Key: Word;
  154.     Shift: TShiftState);
  155. begin
  156.     if key = VK_Escape then Close;
  157. end;
  158.  
  159. procedure TfrmText.FormPaint(Sender: TObject);
  160. begin
  161.     with canvas do
  162.     begin
  163.         { Paint red areas of form }
  164.         Pen.Color := clRed;
  165.         Brush.Color := clRed;
  166.         Brush.Style := bsSolid;
  167.         Rectangle(60, 0, width, 160);        // Delphi
  168.  
  169.         Rectangle(312, 155,  365, 195);        // P extension
  170.  
  171.         Rectangle( 48, 195,  76, 260);        // Dot after M
  172.         Rectangle(126, 195, 154, 260);        // Dot after A
  173.         Rectangle(205, 195, 233, 260);        // Dot after G
  174.         Rectangle(283, 195, 309, 260);        // Dot after A
  175.         Rectangle(355, 195, 382, 260);        // Dot after Z
  176.         Rectangle(410, 195, 438, 260);        // Dot after I
  177.         Rectangle(486, 195, 516, 260);        // Dot after N
  178.     end;
  179.  
  180. end;
  181.  
  182. end.
  183.